//
//  BaseLocationUtils.m
//  jetour_line
//
//  Created by aha on 2023/6/18.
//
#import <AMapFoundationKit/AMapFoundationKit.h>

#import <AMapLocationKit/AMapLocationKit.h>

#import "BaseLocationUtils.h"
#import <MAMapKit/MAMapKit.h>
#import <AMapFoundationKit/AMapFoundationKit.h>

@interface BaseLocationUtils()
@property (nonatomic, strong) AMapLocationManager *locationManager;
@end
@implementation BaseLocationUtils
- (AMapLocationManager *)locationManager{
    if(_locationManager == nil){
        _locationManager =  [[AMapLocationManager alloc] init];
        //设置期望定位精度
        //   定位超时时间，最低2s，此处设置为2s
        _locationManager.locationTimeout =2;
        //   逆地理请求超时时间，最低2s，此处设置为2s
        _locationManager.reGeocodeTimeout = 2;
        [_locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
//        [_locationManager setDesiredAccuracy:kCLLocationAccuracyBest];// 带逆地理信息的一次定位（返回坐标和地址信息）

    }return _locationManager;
}
- (instancetype)init{
    if(self == nil){
        self = [super init];
    }return self;
}
- (void)startLocation:(LocationCallBack)callBack{
    [MAMapView updatePrivacyShow:AMapPrivacyShowStatusDidShow privacyInfo:AMapPrivacyInfoStatusDidContain];
    [MAMapView updatePrivacyAgree:AMapPrivacyAgreeStatusDidAgree];
    // 带逆地理（返回坐标和地址信息）。将下面代码中的 YES 改成 NO ，则不会返回地址信息。
    [self.locationManager requestLocationWithReGeocode:NO completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error) {
        int code =error.code;
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        if (error)
        {
           
            if (error.code == AMapLocationErrorLocateFailed){
                
            }
        }
        if (location)
        {
            [dic setValue:@"startLocation" forKey:@"method"];
            [dic setValue:[NSNumber numberWithDouble:location.coordinate.latitude] forKey:@"lat"];
            [dic setValue:[NSNumber numberWithDouble:location.coordinate.longitude] forKey:@"lng"];
        }
        callBack(dic);
    }];

}
@end
